home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib25 / calloc.c < prev    next >
C/C++ Source or Header  |  1992-09-05  |  955b  |  40 lines

  1. /* from the TOS GCC library */
  2. /* malloc, free, realloc: dynamic memory allocation */
  3. /* 5/2/92 sb -- modified for Heat-n-Serve C to accomodate its 16-bit size_t */
  4. /* 5/5/92 sb -- calloc() gets its own file to reduce library drag */
  5.  
  6. #include <compiler.h>
  7. #include <stddef.h>    /* for size_t */
  8. #include <memory.h>
  9. #include <string.h>
  10.  
  11. __EXTERN void *_malloc __PROTO((unsigned long));
  12. __EXTERN void _bzero __PROTO((void *, unsigned long));
  13. __EXTERN void *_calloc __PROTO((unsigned long, unsigned long));
  14.  
  15. #ifdef __GNUC__
  16. asm(".stabs \"_calloc\",5,0,0,__calloc"); /* dept of clean tricks */
  17. #endif
  18.  
  19. void * _calloc(n, sz)
  20. unsigned long n, sz;
  21. {
  22.   void *r;
  23.   unsigned long total;
  24.   extern void _bzero();
  25.  
  26.   total = n * sz;
  27.   if ((r = _malloc(total)) != NULL) {
  28.     _bzero(r, total);
  29.   }
  30.   return(r);
  31. }
  32.  
  33. #ifndef __GNUC__
  34. void * calloc(n, sz)
  35. size_t n, sz;
  36. {
  37.   return _calloc((unsigned long) n, (unsigned long) sz);
  38. }
  39. #endif
  40.